//
//  zynAVPlayerSingleton.m
//  The Station Agent
//
//  Created by dllo on 16/3/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "zynAVPlayerSingleton.h"
#import <AVFoundation/AVFoundation.h>
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
@interface zynAVPlayerSingleton ()

@end
@implementation zynAVPlayerSingleton
+ (instancetype)sharePlayer {
    
    static zynAVPlayerSingleton *player = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        player = [[zynAVPlayerSingleton alloc] init];
    });
    return player;
    
}
- (instancetype)init {
    self = [super init];
    self.player = [AVPlayer playerWithPlayerItem:self.playerItem];
    
    return self;
}

- (void)playerWithUrl:(NSString *)url {
    
    url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    NSURL *urlstr =[NSURL URLWithString:url];
    
    //创建视频项目对象
    self.playerItem = [[AVPlayerItem alloc] initWithURL:urlstr];
    
    //创建视频播放器对象
    
    [self.player replaceCurrentItemWithPlayerItem:self.playerItem];
 
    [self.player play];
    
}


- (void)removeObserver {
    [self.player removeTimeObserver:self.observerName];
    
    
}
@end
